home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-10-05 | 5.0 KB | 203 lines | [TEXT/MMCC] |
- /****
- * CLaughsDoc.cp
- *
- * Implementation of a document class full of laughs.
- *
- * Copyright © 1994 NeoLogic Systems. All rights reserved.
- *
- * NOTE: This sample application uses the SIOUX serial i/o emulator for outputing
- * text using printf. There are a number of bugs in this mechanism which causes
- * rather unusual behavior.
- *
- * While Laughs includes all the code necessary to open new and pre-existing files,
- * these SIOUX bugs do not allow Laughs' application menu to be accessible. The
- * application can not open pre-existing files as a result. The only possible work
- * around for this bug would be to comment out all printf statements and the call
- * to SendAEQuit in CLaughsDoc::newDatabase. The application will function correctly,
- * though no output will be written to the screen.
- *
- * The window can't be moved on the screen. SIOUX ignores mouse clicks directed
- * to the window.
- *
- * The Save menu item saves the text in the window NOT the NeoAccess database
- * that this application uses.
- *
- ****/
-
- #include "NeoTypes.h"
- #include <stdlib.h>
- #include <stdio.h>
- #include CNeoDatabaseNativeH
- #include CNeoIndexIteratorH
- #include CNeoSelectH
- #include "CLaughsApp.h"
- #include "CLaughsDoc.h"
- #include "CPerson.h"
-
- /***
- * CLaughsDoc
- *
- * This is the document's initialization method.
- *
- ***/
- CLaughsDoc::CLaughsDoc(const Boolean aPrintable, const Boolean newDatabase, const Boolean aRemote)
- : CNeoDocRoot(kLaughsSig, kLaughsFileType, aPrintable, newDatabase)
- {
- }
-
- /***
- * buildWindow
- *
- * This is the auxiliary window-building method that the
- * newDatabase and openFile methods use to create a window.
- *
- * Laughs doesn't need to explicitly create a window,
- * printf will do that for us.
- ***/
- void CLaughsDoc::buildWindow(void)
- {
- // Nothing to do.
- }
-
- /***
- * newDatabase
- *
- * When the user chooses New from the File menu, the createDocument
- * method in your Application class will send a newly created document
- * this message.
- *
- ***/
- void CLaughsDoc::newDatabase(void)
- {
- CNeoDatabase * database = getDatabase();
- NeoFileSpec spec;
-
- fNewDatabase = TRUE;
- fOpenMode = fsRdWrPerm;
- inherited::newDatabase();
-
- // Set the default name which appears in the get file dialog.
- spec.vRefNum = 0;
- spec.parID = 0;
- NeoStringCopy("\pLaughter", spec.name);
- database->setFileSpec(spec);
-
- // Stuff the database with objects.
- createObjects();
-
- // Commit the changes that we made to the database.
- DoSave();
-
- // That's all folks!
- printf("\nDone!\n\n");
-
- // We need to do this due to a bug in SIOUX.
- // ((LApplication *)GetSuperCommander())->SendAEQuit();
- }
-
- /***
- * openFile
- *
- * When the user chooses Open… from the File menu, the OpenDocument()
- * method in your application will let the user choose a file
- * and then send a newly created document this message. The information
- * about the file is in the FSSpec record.
- *
- * In this method, you need to open the file and display its contents
- * in a window. This method uses the auxiliary window-building method.
- *
- ***/
-
- void CLaughsDoc::openFile(FSSpec *aSpec)
- {
- fOpenMode = fsRdPerm;
- inherited::openFile(aSpec);
-
- // Find each of the objects in the database in turn.
- printOut();
-
- // That's all folks!
- printf("\nDone!\n\n");
- }
-
- /***
- * createObjects
- *
- * Add three objects to the database, two jokers and a clown, then commit
- * the changes to disk.
- *
- ***/
- void CLaughsDoc::createObjects(void)
- {
- CJoker * joker;
- CClown * clown;
- CNeoDatabase * database = getDatabase();
- CNeoString string;
- char name[64];
-
- // Tell them what we're about to do.
- database->getName(string);
- BlockMove(&string[1], name, string[0]);
- name[string[0]] = 0;
- printf("Storing 2 Jokers & a Clown in \"%s\".\n", name);
-
- // Create a joker object.
- joker = new CJoker("Jack", 1);
- // Add it to the database.
- database->addObject(joker);
- // Don't need this guy any more. Remove our reference to it.
- joker->unrefer();
- joker = nil;
-
- // Create a clown.
- clown = new CClown("Fred", 2);
- // Add it to the database.
- database->addObject(clown);
- // Remember to remove our reference when we're done.
- clown->unrefer();
- clown = nil;
-
- // Create another joker.
- joker = new CJoker("Harry", 3);
- joker->setJoke("The world’s shortest poem: Flees. Adam had'em");
- // Add it to the database.
- database->addObject(joker);
- // Remove our reference.
- joker->unrefer();
- joker = nil;
- }
-
- /***
- * printOut
- *
- * Find in turn each of the three objects in the database, two jokers and
- * a clown, then commit the changes to disk.
- *
- ***/
- void CLaughsDoc::printOut(void)
- {
- NeoID loop;
- CPerson * person;
- CNeoDatabase * database = getDatabase();
- CNeoString string;
- char name[64];
-
- // Tell them what we're about to do.
- database->getName(string);
- BlockMove(&string[1], name, string[0]);
- name[string[0]] = 0;
- printf("Restoring %ld Jokers & %ld Clowns from \"%s\".\n",
- database->getObjectCount(kJokerID, FALSE),
- database->getObjectCount(kClownID, FALSE), name);
-
- for (loop = 1; loop <= 3; loop++) {
- person = (CPerson *)CNeoPersist::FindByID(database, kPersonID, loop, TRUE);
- if (person) {
- person->printName();
- person->skill();
- printf("\n");
- }
- }
- }
-
-